/*
@(#)BizException   2023-04-19
 
Copyright (c) 2011-2023 杭州湖畔网络技术有限公司 
保留所有权利 
本软件为杭州湖畔网络技术有限公司所有及包含机密信息，须遵守其相关许可证条款进行使用。
Copyright (c) 2011-2023 HUPUN Network Technology CO.,LTD.
All rights reserved.
This software is the confidential and proprietary information of HUPUN
Network Technology CO.,LTD("Confidential Information").  You shall not
disclose such Confidential Information and shall use it only in
accordance with the terms of the license agreement you entered into with HUPUN.
Website：http://www.hupun.com
*/
package org.obp.core.exception;

import io.swagger.annotations.ApiModelProperty;
import lombok.Data;
import org.obp.core.result.ApiResult;
import org.slf4j.MDC;

/**
 * @author: Jackey 2023/4/19
 */
@Data
public class BizException extends RuntimeException {

    private static final long serialVersionUID = -3697924501642645015L;

    @ApiModelProperty("状态码")
    private int code;

    @ApiModelProperty("数据对象")
    private Object data;

    @ApiModelProperty("错误信息")
    private I18nExcEnum i18nExcEnum;

    @ApiModelProperty("链路追踪ID")
    private String traceId;

    public BizException(String message) {
        super(message);
        this.traceId = MDC.get(ApiResult.TRACE_ID);
    }

    public BizException(int code, String message) {
        super(message);
        this.code = code;
        this.traceId = MDC.get(ApiResult.TRACE_ID);
    }

    public BizException(Object data, int code, String message) {
        super(message);
        this.data = data;
        this.code = code;
        this.traceId = MDC.get(ApiResult.TRACE_ID);
    }

    public BizException(I18nExcEnum i18nExcEnum) {
        super(i18nExcEnum.getMessage(false));
        this.code = i18nExcEnum.getCode();
        this.i18nExcEnum = i18nExcEnum;
        this.traceId = MDC.get(ApiResult.TRACE_ID);
    }

    public BizException(Object data, I18nExcEnum i18nExcEnum) {
        super(i18nExcEnum.getMessage(false));
        this.data = data;
        this.code = i18nExcEnum.getCode();
        this.i18nExcEnum = i18nExcEnum;
        this.traceId = MDC.get(ApiResult.TRACE_ID);
    }

}